//
//  ChooseVIPViewController.m
//  MagazineShangejie
//
//  Created by wen on 15/10/28.
//  Copyright © 2015年 CnbizMedia. All rights reserved.
//

#import "ChooseVIPViewController.h"
#import "PayTheVIPViewController.h"
#import "WaitingToPayViewController.h"
#import "Util.h"
@interface ChooseVIPViewController (){
    
    NSString *groupid;
    NSMutableArray *vipArray;
    
    NSMutableArray *svipArray;
    
    NSMutableArray *cellheightArray;
    
    
    __weak IBOutlet UILabel *heightLabel;
}
@property (weak, nonatomic) IBOutlet UIView *theButtonBackView;


@property (weak, nonatomic) IBOutlet UIButton *BackVIPButton;
@property (weak, nonatomic) IBOutlet UIButton *BackSVIPButton;
@property (weak, nonatomic) IBOutlet UIButton *VIPButton;
@property (weak, nonatomic) IBOutlet UIButton *SVIPButton;




@property (weak, nonatomic) IBOutlet UITableView *wordTableView;

@end

@implementation ChooseVIPViewController

-(void)viewWillLayoutSubviews{
    [super viewWillLayoutSubviews];
    
    
    
    
    int white = (self.view.frame.size.width - 276) / 3;
    
    NSLog(@" white %d",white);
    _VIPButton.frame = CGRectMake(white, 10, 138, 92);
    _SVIPButton.frame = CGRectMake(white + 138 + white, 10, 138, 92);
    
    _BackVIPButton.frame = CGRectMake(white, 10, 138, 92);
    _BackSVIPButton.frame = CGRectMake(white + 138 + white, 10, 138, 92);
    
    
    
}

- (void)lodeNews{
    
    NSString*url;
    NSMutableDictionary*parameter;
    url=@"Local/VipInfo";
    
    [[AppAPIClient sharedClient] GET:url parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        
        NSMutableDictionary *result = responseObject[@"data"];
        
        NSLog(@"result -=-= %@",result);
        NSLog(@"parameter ==++ %@",parameter);
        NSLog(@"operation ==++ %@",operation);
        
//        if([result isKindOfClass:[NSNull class]] || [result count] == 0 ){
        
            vipArray = result[@"vip"];
            svipArray = result[@"svip"];
            NSLog(@"vipArray -=-= %@",vipArray);
            NSLog(@"svipArray -=-= %@",svipArray);
            [SVProgressHUD dismiss];
            [self.wordTableView reloadData];
//            return;
//        }
        
        [SVProgressHUD dismiss];
        
        NSLog(@"加载完成");
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"ERR: %@",operation.responseString);
        
        [SVProgressHUD showErrorWithStatus:@"网络错误"];
    }];
    
    
}


- (void)viewDidLoad {
    [super viewDidLoad];
    [super viewDidLoad];
    self.title = @"我的特权";
    _VIPButton.hidden = YES;
    groupid = @"9";
    vipArray = [[NSMutableArray alloc] init];
    svipArray = [[NSMutableArray alloc] init];
    cellheightArray = [[NSMutableArray alloc] init];
    
    
    [UserDefaults setValue:@"VIP" forKey:@"VIP"];
    NSDictionary *Goodorder = [UserDefaults objectForKey:@"Goodorder"];
    NSDictionary *DiamondOrder = [UserDefaults objectForKey:@"DiamondOrder"];
    NSLog(@"Goodorder _+%@",Goodorder);
    NSLog(@"DiamondOrder _+%@",DiamondOrder);
    
    
    //自定义bar按钮
    UIButton *buttonf=[UIButton buttonWithType:UIButtonTypeCustom];
    [buttonf setFrame:CGRectMake(0, 0, 22, 22)];
    [buttonf addTarget:self action:@selector(popOfDismss) forControlEvents:UIControlEventTouchUpInside];
    [buttonf setImage:[UIImage imageNamed:@"dismiss"] forState:UIControlStateNormal];
    UIBarButtonItem*leftBarItem = [[UIBarButtonItem alloc]initWithCustomView:buttonf];
    self.navigationItem.leftBarButtonItem=leftBarItem;
    
    
    //添加返回手势
    UISwipeGestureRecognizer *recognizer = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(popOfDismss)];
    [recognizer setDirection:(UISwipeGestureRecognizerDirectionRight)];
    [[self view] addGestureRecognizer:recognizer];
    
    [self lodeNews];
    
}

-(void)handleSwipeFrom:(UISwipeGestureRecognizer *)recognizer{
    
    if(recognizer.direction==UISwipeGestureRecognizerDirectionRight) {
        CATransition*transition=[CATransition animation];
        transition.duration=1;
        transition.timingFunction=[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
        transition.type=kCATransitionPush;
        transition.subtype=kCATransitionFromLeft;//方向
        [self.view.layer addAnimation:transition forKey:nil];
        //        [self popOfDismss];
        //        [self dismissViewControllerAnimated:YES completion:^{
        //        [SVProgressHUD dismiss];
        //        }];
        
    }
}

-(void)popOfDismss{
    
    //    NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
    //    NSInteger number = [userDefault integerForKey:@"underBarShow"];
    //
    //    if (number == 1) {
    //设置通知，显示tabbar
    [[NSNotificationCenter defaultCenter] postNotificationName:@"showBootomBar" object:self userInfo:nil ];
    
    //    }
    
    if ([[self.navigationController viewControllers] count]>=2) {
        //        self.hidesBottomBarWhenPushed = NO;
        [self.navigationController popViewControllerAnimated:YES];
        
    }else{
        //        self.hidesBottomBarWhenPushed = NO;
        [self dismissViewControllerAnimated:YES completion:nil];
    }
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    self.hidesBottomBarWhenPushed = NO;
    // Dispose of any resources that can be recreated.
}



- (IBAction)chooseVIP:(id)sender {
    _VIPButton.hidden = YES;
    _SVIPButton.hidden = NO;
    groupid = @"9";
    
    //    _VIPUser.text = @"铂金用户";
    //
    //    _jingpinUP.text = @"媒体服务 ";
    //    //    _jingpinDOWN.text = @"看商界APP焦点位置报道一次";
    //    _meiti1.text = @" ";
    //    _meiti2.text = @" ";
    //
    //    _zhihuiUP.text = @"智慧传播 ";
    //    _zhiHui.text = @"区域经济创新论坛 (当地每年一场) VIP席位1位";
    //    //    _zhihuiDOWN.text = @"中国最佳商业模式峰会 (全国每年一场) 坐席1位             中国产品创新高峰论坛 (全国每年一场) 坐席1位             区域经济创新论坛 (当地每年一场) VIP席位1位";
    //
    //    _studyUP.text = @"学习进阶 ";
    //    _xuexi1.text = @"商业模式特训营 (当地每年六场) 坐席1位";
    //    _xuexi2.text = @"世华智业总裁思维风暴 (当地每年1场) 坐席1位";
    //    //    _studyDOWN.text = @"商业模式特训营 (当地每年六场) 坐席1位                       世华智业总裁思维风暴 (当地每年1场) 坐席1位                 国内知名企业参访 (每年两次) 名额1位";
    //
    //    _zhiyuanUP.text = @"资源整合 ";
    //    _ziyuan1.text = @"";
    //    _ziyuan2.text = @"";
    //    _zhiyuanDOWN.text = @"商界创投沙龙 (当地每年四场) 坐席1位                            行业创新沙龙 (当地不定期举办) 坐席1位                       商界时尚之夜 (当地不定期举办) 坐席1位    		                    	    看商界APP线上会员专属功能";
    
    
    [UserDefaults setValue:@"VIP" forKey:@"VIP"];
    [_wordTableView reloadData];
}


- (IBAction)chooseSVIP:(id)sender {
    _VIPButton.hidden = NO;
    _SVIPButton.hidden = YES;
    groupid = @"10";
    
    
    //    _VIPUser.text = @"钻石用户";
    //    _jingpinUP.text = @"媒体服务 ";
    //    //    _jingpinDOWN.text = @"每年12期《商界》、《商界评论》和《商界时尚》杂志     每年12本由《商界》杂志精选的商业财经书籍";
    //    _meiti1.text = @"《商界》杂志采访报道一次 ";
    //    _meiti2.text = @"商界系投资基金资本导航顾问服务";
    //
    //    _zhihuiUP.text = @"智慧传播 ";
    //    _zhiHui.text = @"区域经济创新论坛 (当地每年一场) 特邀演讲嘉宾";
    //    //    _zhihuiDOWN.text = @"中国最佳商业模式峰会 (全国每年一场) 坐席1位            中国产品创新高峰论坛 (全国每年一场) 坐席1位            区域经济创新论坛 (当地每年一场) 特邀演讲嘉宾";
    //
    //    _studyUP.text = @"学习进阶 ";
    //    _xuexi1.text = @"商业模式特训营 (当地每年六场) VIP坐席1位";
    //    _xuexi2.text = @"世华智业总裁思维风暴 (当地每年1场) VIP坐席1位";
    //    //    _studyDOWN.text = @"商业模式特训营 (当地每年六场) VIP坐席1位                 世华智业总裁思维风暴 (当地每年1场) VIP坐席1位                 国内知名企业参访 (每年两次) 名额1位";
    //
    //    _zhiyuanUP.text = @"资源整合 ";
    //    _ziyuan1.text = @"商界私董会 (当地每年四场) 坐席1位";
    //    _ziyuan2.text = @"商界俱乐部区域分会副会长级身份授予";
    //    _zhiyuanDOWN.text = @"商界私董会 (当地每年四场) 坐席1位                                  商界俱乐部区域分会副会长级身份授予                               商界创投沙龙 (当地每年四场) 坐席1位                           行业创新沙龙 (当地不定期举办) 坐席1位                           商界时尚之夜 (当地不定期举办) 坐席1位                       			看商界APP线上会员专属功能";
    
    
    [UserDefaults setValue:@"SVIP" forKey:@"VIP"];
    [_wordTableView reloadData];
}


- (IBAction)VIPButtonEvent:(id)sender {
    [SVProgressHUD show];
    
    
    if (IFUserLogin) {
        NSLog(@"[UserDefaults objectForKey: ] %@",[UserDefaults objectForKey:@"user"]);
        
        //保存了电话号码的情况
        NSString *mobile = [[UserDefaults objectForKey:@"user"] objectForKey:@"mobile"];
        if ( mobile.length > 1) {
            
            
            if ([[[UserDefaults objectForKey:@"user"] objectForKey:@"groupid"] isEqualToString:@"10"]) {
                //已经是铂金用户
                [SVProgressHUD showErrorWithStatus:@"您已经是钻石用户"];
                
                return;
            }
            
            if ([[[UserDefaults objectForKey:@"user"] objectForKey:@"groupid"] isEqualToString:@"9"]) {
                //已经是铂金用户
                [SVProgressHUD showErrorWithStatus:@"您已经是铂金用户"];
                return;
            }
            
            else {
                
                //检测是否有订单
                [self checkOrder];
                
                
            }
        }
        
        //没有登记电话号码，到保存电话号码的界面
        else{
            UIStoryboard*story=[UIStoryboard storyboardWithName:@"Main" bundle:nil];
            LoginViewController*login=[story instantiateViewControllerWithIdentifier:@"BindingPhoneViewController"];
            UINavigationController*nav=[[UINavigationController alloc]initWithRootViewController:login];
            [self.navigationController pushViewController:login animated:YES];
            [SVProgressHUD dismiss];
            //            [self presentViewController:nav animated:YES completion:nil];
            
        }
    }
    
    //没有登录，跳转到登录界面
    else{
        UIStoryboard*story=[UIStoryboard storyboardWithName:@"Main" bundle:nil];
        LoginViewController*login=[story instantiateViewControllerWithIdentifier:@"LoginViewController"];
        UINavigationController*nav=[[UINavigationController alloc]initWithRootViewController:login];
        //        [self.navigationController pushViewController:login animated:YES];
        
        [self presentViewController:nav animated:YES completion:nil];
    }
    
}


- (IBAction)SVIPButtonEvent:(id)sender {
    
    [SVProgressHUD show];
    if (IFUserLogin) {
        
        //保存了电话号码的情况
        NSString *mobile = [[UserDefaults objectForKey:@"user"] objectForKey:@"mobile"];
        if ( mobile.length > 1) {
            if ([[[UserDefaults objectForKey:@"user"] objectForKey:@"groupid"] isEqualToString:@"10"]) {
                //已经是铂金用户
                [SVProgressHUD showErrorWithStatus:@"您已经是钻石用户"];
                return;
            }
            else {
                
                
                //检测是否有订单
                [self checkOrder];
                
                
            }
        }
        
        //没有登记电话号码，到保存电话号码的界面
        else{
            UIStoryboard*story=[UIStoryboard storyboardWithName:@"Main" bundle:nil];
            LoginViewController*login=[story instantiateViewControllerWithIdentifier:@"BindingPhoneViewController"];
            UINavigationController*nav=[[UINavigationController alloc]initWithRootViewController:login];
            [self.navigationController pushViewController:login animated:YES];
            [SVProgressHUD dismiss];
            //            [self presentViewController:nav animated:YES completion:nil];
            
        }
        
        
    }
    
    //没有登录，跳转到登录界面
    else{
        UIStoryboard*story=[UIStoryboard storyboardWithName:@"Main" bundle:nil];
        LoginViewController*login=[story instantiateViewControllerWithIdentifier:@"LoginViewController"];
        UINavigationController*nav=[[UINavigationController alloc]initWithRootViewController:login];
        //        [self.navigationController pushViewController:login animated:YES];
        
        [self presentViewController:nav animated:YES completion:nil];
        
    }
}


- (IBAction)pushToPayMoney:(id)sender {
    
    [SVProgressHUD show];
    
    //登录后的情况
    if (IFUserLogin) {
        
        //保存了电话号码的情况
        NSString *mobile = [[UserDefaults objectForKey:@"user"] objectForKey:@"mobile"];
        if ( mobile.length > 1) {
            
            
            if ([[[UserDefaults objectForKey:@"user"] objectForKey:@"groupid"] isEqualToString:@"10"]) {
                //已经是铂金用户
                [SVProgressHUD showErrorWithStatus:@"您已经是钻石用户"];
                
                return;
            }
            
            if([[[UserDefaults objectForKey:@"user"] objectForKey:@"groupid"] isEqualToString:@"9"]){
                if ([[UserDefaults objectForKey:@"VIP"] isEqualToString:@"VIP"]) {
                    [SVProgressHUD showErrorWithStatus:@"您已经是铂金用户"];
                    
                    return;
                }
                
            }
            
            //检测是否有订单
            [self checkOrder];
            
        }
        
        //没有登记电话号码，到保存电话号码的界面
        else{
            UIStoryboard*story=[UIStoryboard storyboardWithName:@"Main" bundle:nil];
            LoginViewController*login=[story instantiateViewControllerWithIdentifier:@"BindingPhoneViewController"];
            UINavigationController*nav=[[UINavigationController alloc]initWithRootViewController:login];
            [self.navigationController pushViewController:login animated:YES];
            [SVProgressHUD dismiss];
        }
    }
    
    //没有登录，跳转到登录界面
    else{
        UIStoryboard*story=[UIStoryboard storyboardWithName:@"Main" bundle:nil];
        LoginViewController*login=[story instantiateViewControllerWithIdentifier:@"LoginViewController"];
        UINavigationController*nav=[[UINavigationController alloc]initWithRootViewController:login];
        //        [self.navigationController pushViewController:login animated:YES];
        
        [self presentViewController:nav animated:YES completion:nil];
    }
}

- (void)checkOrder{
    
    //查看之前是否生成过订单
    
    
    
    //如果选择的是VIP
    if ([[UserDefaults objectForKey:@"VIP"] isEqualToString:@"VIP"]) {
        groupid = @"9";
        NSDictionary *Goodorder = [UserDefaults objectForKey:@"Goodorder"];
        NSDictionary *Goodaaaccc = [UserDefaults objectForKey:@"Goodaaaccc"];
        //查看订单的状态，如果通过审核就直接跳转支付界面。上传订单号，查看订单状态trial 订单审核状态 0=默认 1=否 2=是
        if ([Goodaaaccc count] > 0) {
            
            [[AppAPIClient sharedClient] GET:@"Payment/OrderCheck" parameters:@{@"sn":[Goodaaaccc objectForKey:@"trade_sn"]} success:^(AFHTTPRequestOperation *operation, id responseObject) {
                NSDictionary *trialdata = responseObject[@"data"];
                NSLog(@"responseObject------%@",responseObject);
                NSLog(@"responseObject ==%@",responseObject);
                NSLog(@"trialdata == %@",trialdata);
                
                
                if ([[trialdata objectForKey:@"trial"] integerValue] == 0) {
                    //正在审核
                    //                    [SVProgressHUD showSuccessWithStatus:@"订单审核失败，请稍后在试。"];
                    //这里要push到一个新的界面
                    [UserDefaults setObject:@"0" forKey:@"trial"];
                    UIStoryboard*story=[UIStoryboard storyboardWithName:@"Main" bundle:nil];
                    WaitingToPayViewController*web=[story instantiateViewControllerWithIdentifier:@"WaitingToPayViewController"];
                    
                    [self.navigationController pushViewController:web animated:YES];
                    
                }
                
                else if ([[trialdata objectForKey:@"trial"] integerValue] == 1) {
                    //没通过审核
                    //                    [SVProgressHUD showSuccessWithStatus:@"订单审核失败，请稍后在试。"];
                    
                    [UserDefaults setObject:@"1" forKey:@"trial"];
                    //这里要push到一个新的界面
                    UIStoryboard*story=[UIStoryboard storyboardWithName:@"Main" bundle:nil];
                    WaitingToPayViewController*web=[story instantiateViewControllerWithIdentifier:@"WaitingToPayViewController"];
                    
                    [self.navigationController pushViewController:web animated:YES];
                    
                }
                else if ([[trialdata objectForKey:@"trial"] integerValue] == 2) {
                    //通过审核
                    
                    //这里要push到一个新的界面
                    UIStoryboard*story=[UIStoryboard storyboardWithName:@"Main" bundle:nil];
                    PayTheVIPViewController*web=[story instantiateViewControllerWithIdentifier:@"PayTheVIPViewController"];
                    
                    [self.navigationController pushViewController:web animated:YES];
                }
                
                [SVProgressHUD dismiss];
            } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
                [SVProgressHUD dismiss];
                [SVProgressHUD showSuccessWithStatus:@"查询订单失败，请稍后在试。"];
            }];
            
        }
        //如果没有订单号则直接生成一个订单号
        else{
            
            
            [self makeOrder];
            
            
        }
        [SVProgressHUD dismiss];
        groupid = @"9";
    }
    
    //如果选择的是SVIP
    else{
        groupid = @"10";
        
        NSDictionary *DiamondOrder = [UserDefaults objectForKey:@"DiamondOrder"];
        NSLog(@"DiamondOrder == %@",DiamondOrder);
        
        
        NSDictionary *Diamondaaaccc = [UserDefaults objectForKey:@"Diamondaaaccc"];
        NSLog(@"Diamondaaaccc == %@",Diamondaaaccc);
        if ([Diamondaaaccc count] > 0) {
            //查看订单的状态，如果通过审核就直接跳转支付界面。如果没有就跳转提示界面，提示用户等待审核
            
            NSString *snsnsn = [Diamondaaaccc objectForKey:@"trade_sn"];
            NSLog(@"snsnsn == %@",snsnsn);
            [[AppAPIClient sharedClient] GET:@"Payment/OrderCheck" parameters:@{@"sn":snsnsn} success:^(AFHTTPRequestOperation *operation, id responseObject) {
                NSLog(@"responseObject------%@",responseObject);
                NSDictionary *trialdata = responseObject[@"data"];
                
                NSLog(@"trialdata == %@",trialdata);
                
                NSLog(@"trialdata objectForKey == %@",[trialdata valueForKey:@"trial"]);
                
                if ([[trialdata objectForKey:@"trial"] integerValue] == 0) {
                    //正在审核
                    //                    [SVProgressHUD showSuccessWithStatus:@"订单审核失败，请稍后在试。"];
                    //这里要push到一个新的界面
                    [UserDefaults setObject:@"0" forKey:@"trial"];
                    UIStoryboard*story=[UIStoryboard storyboardWithName:@"Main" bundle:nil];
                    WaitingToPayViewController*web=[story instantiateViewControllerWithIdentifier:@"WaitingToPayViewController"];
                    
                    [self.navigationController pushViewController:web animated:YES];
                    
                }
                if ([[trialdata objectForKey:@"trial"] integerValue] == 1) {
                    //没通过审核
                    //                    [SVProgressHUD showSuccessWithStatus:@"订单审核失败，请稍后在试。"];
                    //这里要push到一个新的界面
                    [UserDefaults setObject:@"1" forKey:@"trial"];
                    UIStoryboard*story=[UIStoryboard storyboardWithName:@"Main" bundle:nil];
                    WaitingToPayViewController*web=[story instantiateViewControllerWithIdentifier:@"WaitingToPayViewController"];
                    
                    [self.navigationController pushViewController:web animated:YES];
                    
                }
                else if ([[trialdata objectForKey:@"trial"] integerValue] == 2) {
                    //通过审核
                    
                    //这里要push到一个新的界面
                    UIStoryboard*story=[UIStoryboard storyboardWithName:@"Main" bundle:nil];
                    PayTheVIPViewController*web=[story instantiateViewControllerWithIdentifier:@"PayTheVIPViewController"];
                    
                    [self.navigationController pushViewController:web animated:YES];
                    
                }
                
                [SVProgressHUD dismiss];
            } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
                [SVProgressHUD dismiss];
                [SVProgressHUD showSuccessWithStatus:@"查询订单失败，请稍后在试。"];
            }];
        }
        //如果没有订单就去生成一个
        else{
            
            [self makeOrder];
        }
        [SVProgressHUD dismiss];
        groupid = @"10";
    }
    
}

- (void)makeOrder
{
    [[AppAPIClient sharedClient] POST:@"Payment/CreateOrder" parameters:@{@"userid":[[UserDefaults objectForKey:@"user"] objectForKey:@"userid"],@"groupid":groupid} success:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSMutableDictionary *order = responseObject[@"data"];
        
        NSLog(@"order == %@",order);
        NSMutableDictionary *aaaccc = [[NSMutableDictionary alloc] init];
        [aaaccc addEntriesFromDictionary:order];
        if ([groupid isEqualToString:@"9"]) {
            [UserDefaults setObject:aaaccc forKey:@"GoodOrder"];
            [UserDefaults setObject:aaaccc forKey:@"Goodaaaccc"];
        }
        else{
            [UserDefaults setObject:aaaccc forKey:@"DiamondOrder"];
            [UserDefaults setObject:aaaccc forKey:@"Diamondaaaccc"];
        }
        
        NSDictionary *Goodorder = [UserDefaults objectForKey:@"Goodorder"];
        NSDictionary *DiamondOrder = [UserDefaults objectForKey:@"DiamondOrder"];
        NSLog(@"Goodorder _-+%@",Goodorder);
        NSLog(@"DiamondOrder _-+%@",DiamondOrder);
        
        //                [SVProgressHUD showSuccessWithStatus:@"生成订单成功"];    到审核界面，提示用户等待审核
        
        [UserDefaults setObject:@"0" forKey:@"trial"];
        
        UIStoryboard*story=[UIStoryboard storyboardWithName:@"Main" bundle:nil];
        WaitingToPayViewController*web=[story instantiateViewControllerWithIdentifier:@"WaitingToPayViewController"];
        
        [self.navigationController pushViewController:web animated:YES];
        
        [SVProgressHUD dismiss];
        //                [self popOfDismss];
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        [SVProgressHUD dismiss];
        [SVProgressHUD showSuccessWithStatus:@"生成订单失败，请稍后在试。"];
    }];
}

#pragma mark - Table view data source

-(UIView*)tableHeader{
    UIView*view=[[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 45)];
    UILabel *vipLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 60, 25)];
    if ([groupid isEqualToString:@"9"]) {
        vipLabel.text = @"铂金用户";
    }
    else{
        vipLabel.text = @"钻石用户";
    }
    [view addSubview:vipLabel];
    return view;
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    if (section==0) {
        return [self tableHeader];
    }else{
        return nil;
    }
    
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    //#warning Potentially incomplete method implementation.
    // Return the number of sections.
    
    return 1;
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    //#warning Incomplete method implementation.
    //     Return the number of rows in the section.
    
    if ([groupid isEqualToString:@"9"]) {
        return [vipArray count];
    }
    else{
        return [svipArray count];
    }
    return 4;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    NSMutableArray *theArray = [[NSMutableArray alloc] init];
    
    if ([groupid isEqualToString:@"9"]) {
        theArray = [vipArray copy];
    }
    else{
        theArray = [svipArray copy];
    }
    
    NSDictionary *cellDic = [[NSDictionary alloc] init];
    cellDic = theArray[indexPath.row];
    NSLog(@"cellDic == %@",cellDic);
    heightLabel.text = cellDic[@"info"];
    
    [heightLabel setNumberOfLines:0];
    
    heightLabel.lineBreakMode = NSLineBreakByWordWrapping;
    
    NSLog(@"heightLabel.text == %@",heightLabel.text);
    
    
    UIFont *fnt = [UIFont fontWithName:@"HelveticaNeue" size:14.0f];
    heightLabel.font = fnt;
    
    NSLog(@"1heightLabel.frame.size.height == %f 1heightLabel.frame.size.width == %f",heightLabel.frame.size.height,heightLabel.frame.size.width);
    CGSize size = [heightLabel sizeThatFits:CGSizeMake(300, MAXFLOAT)];
    
    heightLabel.frame =CGRectMake(heightLabel.frame.origin.x, heightLabel.frame.origin.y, heightLabel.frame.size.width, size.height);
    heightLabel.font = [UIFont systemFontOfSize:15];
    
    NSLog(@"2heightLabel.frame.size.height == %f 2heightLabel.frame.size.width == %f",heightLabel.frame.size.height,heightLabel.frame.size.width);
    int abc = heightLabel.frame.size.height + 70;// / 20.0f  * 16
    NSLog(@"wordLabel.lineBreakMode %ld",(long)heightLabel.lineBreakMode);
    
    heightLabel.hidden = YES;
    
    NSLog(@"abc %d",abc);
    NSLog(@"indexPath.row %ld",(long)indexPath.row);
    return abc;
    
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    return 0;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    UITableViewCell *cell ;
    cell = [tableView dequeueReusableCellWithIdentifier:@"moneycell" forIndexPath:indexPath];
    
    if (cell==nil) {
        
        cell=[tableView dequeueReusableCellWithIdentifier:@"moneycell"];
    }
    
    NSMutableArray *theArray = [[NSMutableArray alloc] init];
    
    if ([groupid isEqualToString:@"9"]) {
        theArray = [vipArray copy];
    }
    else{
        theArray = [svipArray copy];
    }
    
    NSDictionary *cellDic = [[NSDictionary alloc] init];
    cellDic = theArray[indexPath.row];
    NSLog(@"cellDic == %@",cellDic);
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    UILabel *title = (UILabel *)[cell.contentView viewWithTag:1];
    title.text = cellDic[@"title"];
    
    
    NSString *infoString1 = cellDic[@"info"];
    NSString *infoString2 = [infoString1 stringByReplacingOccurrencesOfString:@"\\n" withString:@"\n"];
    
    UILabel *wordLabel = (UILabel *)[cell.contentView viewWithTag:2];
    wordLabel.text = infoString2;
    NSLog(@"wordLabel.text == %@",wordLabel.text);
    
    UIImageView *lineImage = (UIImageView *)[cell.contentView viewWithTag:3];
    
    [lineImage sd_setImageWithURL:[NSURL URLWithString:cellDic[@"icon"]]];
//    lineImage.image = [UIImage imageNamed:cellDic[@"icon"]];
    
    [wordLabel setNumberOfLines:0];
    
    
    CGSize size = [cell.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize];
    
    
    //        [wordLabel setFrame:CGRectMake(10, 0, size.width, size.height+30)];
    
    NSLog(@"size.height == %f",size.height);
    
//    if (cellheightArray.count <= 4) {
//        cellheightArray [indexPath.row] = [NSString stringWithFormat:@"%f", size.height ];
//        
//        [_wordTableView reloadData];
//    }
//    
    
    
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
    
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
